home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / rain_for.swf / scripts / __Packages / smashing / ClipHandler.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  2.3 KB  |  97 lines

  1. class smashing.ClipHandler
  2. {
  3.    var offset;
  4.    var home;
  5.    var clips;
  6.    var openSlots;
  7.    var id;
  8.    static var nId = 0;
  9.    function ClipHandler(objHome, nOffset)
  10.    {
  11.       if(nOffset == undefined)
  12.       {
  13.          nOffset = 0;
  14.       }
  15.       this.offset = nOffset;
  16.       this.home = objHome;
  17.       this.clips = [];
  18.       this.openSlots = [];
  19.       this.id = smashing.ClipHandler.nId++;
  20.    }
  21.    function findFirstEmpty()
  22.    {
  23.       var _loc2_ = 0;
  24.       if(this.openSlots.length == 0)
  25.       {
  26.          _loc2_ = this.clips.length;
  27.       }
  28.       else
  29.       {
  30.          _loc2_ = this.openSlots.pop();
  31.       }
  32.       return _loc2_;
  33.    }
  34.    function addClip(sName)
  35.    {
  36.       var _loc2_ = this.findFirstEmpty();
  37.       if(this.clips[_loc2_] != null)
  38.       {
  39.       }
  40.       var _loc4_ = _loc2_ + this.offset;
  41.       var _loc0_ = null;
  42.       var _loc3_ = this.clips[_loc2_] = this.home.attachMovie(sName,"clip" + _loc2_ + Math.floor(60000 * Math.random()),_loc4_);
  43.       _loc3_.nId = _loc2_;
  44.       _loc3_.handler = this;
  45.       return this.clips[_loc2_];
  46.    }
  47.    function removeClip(mc)
  48.    {
  49.       if(mc.handler != null)
  50.       {
  51.          if(mc.handler.id == this.id)
  52.          {
  53.             var _loc2_ = mc.nId;
  54.             this.openSlots.push(_loc2_);
  55.             this.clips[_loc2_].removeMovieClip();
  56.             this.clips[_loc2_] = null;
  57.             return true;
  58.          }
  59.       }
  60.       return false;
  61.    }
  62.    function removeIndex(nIndex)
  63.    {
  64.       if(this.clips[nIndex] != null)
  65.       {
  66.          this.openSlots.push(nIndex);
  67.          this.clips[nIndex].removeMovieClip();
  68.          this.clips[nIndex] = null;
  69.          return true;
  70.       }
  71.       return false;
  72.    }
  73.    function swap(nFirst, nSecond)
  74.    {
  75.       if(this.clips[nFirst] != null && this.clips[nSecond] != null)
  76.       {
  77.          var _loc4_ = this.clips[nFirst];
  78.          this.clips[nFirst] = this.clips[nSecond];
  79.          this.clips[nSecond] = _loc4_;
  80.          this.clips[nFirst].swapDepths(this.clips[nSecond]._name);
  81.       }
  82.    }
  83.    function removeAllClips()
  84.    {
  85.       var _loc2_ = 0;
  86.       while(_loc2_ < this.clips.length)
  87.       {
  88.          this.removeIndex(_loc2_);
  89.          _loc2_ = _loc2_ + 1;
  90.       }
  91.    }
  92.    function toString()
  93.    {
  94.       return "[Cliphandler id:" + this.id + "]";
  95.    }
  96. }
  97.